/**
 * 普通业务模块示例
 */
define(['Util',
        '../common/getMenu',
        'list',
        'comboSelect',
        'form',
        'dialog',
        'tab',
        'loading',
        '../common/getPath',
        '../common/getQueryString',
        'select',
        'cookie',
        'text!tpl/staffing/peoplestaffing.tpl',
        'text!tpl/staffing/editor.tpl',
        'text!tpl/staffing/formation.tpl',
        'simpleTree',
        'text!tpl/staffing/addPeople.tpl',
        'selectTree',
        'text!tpl/staffing/table.tpl',
        'validator',
        '../common/getProjectList',
    ],
    function(Util, getMenu, List, ComboSelect, Form, Dialog, Tab, Loading, AjaxPath, GetQueryString, Select, $cookie, staffTpl, editorTpl, formationTpl, SimpleTree, addPeopleTpl, SelectTree, tabelTpl, Validator, getProjectList) {
        require(['style!css/style.css']);
        var $el = null;

        var _indexModule = null,
            requireList = null,
            developList = null,
            testList = null,
            tab = null,
            oStaffTpl = null,
            handLoading = null,
            loadingConfig = null,
            listConfig = null,
            excuterSelect = null,
            allPeopleList = null,
            dropSelectTo = null,
            dropSelectOgn = null,
            projectId = null,
            staffingAuthority;
        var initialize = function(indexModule, options, tabItem) {

            $el = $(staffTpl);
            _indexModule = indexModule;

            // 事件--点击切换tab后事件回调
            $(tabItem).on("tabActive", function() {              
                tabItem.show(true); // 刷新表单
            });

            tab = tabItem;
            createLoading();
            tplId = options.menuId;

            
            // 业务相关代码
            eventInit();
            this.content = $el;
            
            getStaffingAuthority($el);
            //inProjectList();
            // allListInit();
            // initTpl();
            getMenu(tab, options.menuId);
        };
        var allListInit = function(){
            listInit('requireListContainer');
            requireList = new List(listConfig);
            requireList.search();
            listInit('developListContainer');
            developList = new List(listConfig);
            developList.search();
            listInit('testListContainer');
            testList = new List(listConfig);
            testList.search();
            $(".tabProjectContainer").find("a").removeClass("theSort");
        }
        var initTpl = function(){
            var requireId = null,
                developId = null,
                testId = null;
            projectId = $cookie.get("projectSelectId");
            require(['text!tpl/staffing/table.tpl'], function(tabelTpl){
                Util.ajax.getJson(AjaxPath.project+"/projects/"+projectId+"/users?isLeader=true", {} ,function(result, isok) {
                    // console.log(typeof result.beans[0].project_role_id)
                    if(result.returnCode === "0000"){
                        Util.ajax.getJson(AjaxPath.auth + '/authority/button/'+$cookie.get("userId")+'?datas=[{"mo":"22","btnId":""}]',{},function(json,status){
                            if(json.returnCode === "0000"){
                                var item = {
                                    "beans":{}
                                };
                                for(var i = 0; i < result.beans.length; i++){
                                    if(result.beans[i].project_role_id === 1){
                                        item["beans"]["manager"] = result.beans[i];
                                    } else if(result.beans[i].project_role_id === 2){
                                        item["beans"]["require"] = result.beans[i];
                                        requireId = result.beans[i].userId;
                                    } else if(result.beans[i].project_role_id === 3){
                                        item["beans"]["develop"] = result.beans[i];
                                        developId = result.beans[i].userId;
                                    } else if(result.beans[i].project_role_id === 4){
                                        item["beans"]["test"] = result.beans[i];
                                        testId = result.beans[i].userId;
                                    }
                                }
                                if(json.beans[0].mo === 0){
                                    item["judgeFlag"] = false;
                                    item["ojudgeFlag"] = !item.judgeFlag;  
                                }else {
                                    item["judgeFlag"] = true;
                                    item["ojudgeFlag"] = !item.judgeFlag;
                                }
                                oTableTpl = Util.hdb.compile(tabelTpl)(item);
                                $("#oTabel").html(oTableTpl);
                                // $("#requireEditBtn").attr("odata",item["beans"]["require"]);
                                $("#requireEditBtn").attr("odata",requireId);
                                $("#developEditBtn").attr("odata",developId);
                                $("#testEditBtn").attr("odata",testId);

                                /*require(['js/btnAuthority'], function(oAuthority){
                                    new oAuthority( $("#oTabel") );
                                });*/
                            }
                        });
                    }         
                });              
            });    
        }


        var eventInit = function (){
            //修改按钮
            $el.on('click', '#requireEditBtn', excuterEdit);
            $el.on('click', '#developEditBtn', excuterEdit);
            $el.on('click', '#testEditBtn', excuterEdit);
            //添加人员点击事件
            $el.on('click', '.addStaffing', addStaffing);

            //添加人员中的模糊查询 查询按钮  重置按钮
            $(document).on("click", ".stfBtnSearch", btnSearch);
            $(document).on("click", ".stfBtnReset", btnSearchRest);
            //删除按钮
            $el.on('click', '#delrequire', delDialogBox);
            $el.on('click', '#deldevelop', delDialogBox);
            $el.on('click', '#deltest', delDialogBox);
            $el.on('click', '.oView', viewFormation)
            $el.on('click', '.tabProjectContainer .t-list-title>span.tri', changeSlide)

            $('#tabList li.' + tplId).on('click', tabActive);
        }

        var excuterEdit = function(e){
            creatDialog(e);
        }

        var tabActive = function() {
            inProjectList();
            getMenu(tab, tplId);   
        }

        var createLoading = function() {
            loadingConfig = {
                el: 'body', 
                className: 'loading', 
                position: 'center', 
                width: '300', 
                height: 'auto', 
                mask: 1, 
                animate: 1, 
                mode: 'layer', 
                text: '加载中...', 
                icon: 'dotCycle', 
            }
        }

        var listInit = function(content){
            var projectRoleId = null;
            projectId = $cookie.get("projectSelectId");
            if(content === "requireListContainer"){ projectRoleId = 5 };
            if(content === "developListContainer"){ projectRoleId = 6 };
            if(content === "testListContainer"){ projectRoleId = 7 };
            listConfig = {
                el: $('.'+content, $el),
                ajax: {    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置；慎用
                    method:'GET'
                },
                field: {
                    boxType: 'checkbox',
                    key: 'id',
                    items: [
                    {
                        text: '姓名',
                        title: 'userName',
                        name: 'userName',
                        className: 'w90',
                        sorting:1,
                        width:170,
                        click: function (e, val,item) {
                            creatNameDialog(item);
                            // creatDialog(e, item);
                        },
                        render: function (item, val) {
                            val = $('<span/>').text( val ).html();
                            val = val.replace(/\s/g, '&nbsp;');
                            return '<a href="javascript:;" class="text-overflow" style="line-height:36px;display:block;outline:none">' + val + '</a>';
                        }
                    },
                    {
                        text: '用户名',
                        width:170,
                        title: 'user_account',
                        name: 'userAccount',
                        sorting:1,
                        className: 'w120'
                    },
                    {
                        text: '手机号',
                        width:170,
                        title: 'phone',
                        name: 'phone',
                        className: 'w120',
                        sorting:1
                    },
                    {
                        text: '邮箱',
                        width:170,
                        title: 'email',
                        name: 'email',
                        className: 'w120',
                        sorting:1
                    },
                    {
                        text: '操作',
                        title: '',
                        name: '',
                        width:130,
                        className: 'w120 fn-center',
                        click: function (e, val,item) {
                            $(".sn-list-content-locker.sn-list-show tr.selected").find('td').click();
                            $("."+content+" .sn-list-show table tbody tr").eq(e.currentTarget.parentNode.rowIndex).find('td').click();
                            delDialogBox(e);
                        },
                        render: function (item, val) {
                            if(staffingAuthority){
                                return '<div class="fn-center"><button class="t-btn t-btn-blue t-btn-xs" oId="del'+content+'"><a style="color:#fff">删除</a></button></div>';
                            } else {
                                return '<div class="fn-center">您没有权限操作该项!</div>';
                            }
                        }
                    }]
                },
                page: {
                    customPages: [2, 3, 5, 10, 15, 20, 30, 50], //可选择每页显示多少条
                    perPage: 5, //默认每页显示多少条记录
                    total: true
                },
                data: {
                    url: AjaxPath.project + "/projects/"+projectId+"/users?projectRoleId="+projectRoleId
                    // url:"../../../data/list1.json"
                }
            };
        }

        //修改负责人对话框
        var creatDialog = function(e){
            var oItem = null,
                config = null,
                name = null,
                oData = $(e.currentTarget).attr("odata"),
                newValue = null,
                projectRoleId = null,
                createName = null;
            if( e.currentTarget.id === "requireEditBtn" ){
                name = "需求负责人";
                projectRoleId = 2;
            }else if( e.currentTarget.id === "developEditBtn" ){
                name = "开发负责人";
                projectRoleId = 3;
            }else if( e.currentTarget.id === "testEditBtn" ){
                name = "测试负责人";
                projectRoleId = 4;
            }
            createName = {};
            createName.name = name;
            if(!oData){oData = 0};
                config = {
                    mode: 'normal', 
                    title: '修改'+name, 
                    content: Util.hdb.compile(editorTpl)(createName), 
                    ok: function() {
                        newValue = excuterSelect.getSelected().key;
                        if(!newValue){
                            new Dialog({
                                mode: 'tips',
                                content: '<div style="text-align:center;margin-top:70px">请指定负责人</div>',
                                width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                                height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                                cancelDisplay: false
                            });
                            return false;
                        } else {
                            //oData 为旧值 newValue 为新值
                            Util.ajax.postJson(AjaxPath.project+"/projects/"+projectId+"/updateLeader?userId="+newValue+"&oldUserId="+oData+"&projectRoleId="+projectRoleId, {} ,function(result, isok) {
                                var flag = result.returnCode;
                                if(flag !== '0000') {
                                    new Dialog({
                                        mode: 'tips', //对话框模式，默认normal标准|tips浮动层|tips确认对话框
                                        title: '提示', //对话框标题
                                        width: 300,
                                        height: 150,
                                        content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>', //对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                                        cancelDisplay: false
                                    });
                                    return;
                                } else if(flag === '0000'){
                                    new Dialog({
                                        mode: 'tips',
                                        content: '<div style="text-align:center;margin-top:70px">修改成功!</div>',
                                        width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                                        height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                                        cancelDisplay: false
                                    });
                                    initTpl();
                                    if(e.currentTarget.id === "requireEditBtn"){
                                        requireList.search();
                                        $('.requireListContainer').find('a').removeClass('theSort');
                                    }else if(e.currentTarget.id === "developEditBtn"){
                                        developList.search();
                                        $('.developListContainer').find('a').removeClass('theSort');
                                    }else if(e.currentTarget.id === "testEditBtn"){
                                        testList.search();
                                        $('.testListContainer').find('a').removeClass('theSort');
                                    }
                                }
                            })
                            return true;
                        }
                    }, 
                    cancel: function() {
                        return true;
                    },
                    cancelValue: '取消', 
                    okValue: '提交', 
                    cancelDisplay: true, 
                    width: 600, 
                    height: 300, 
                    maxWidth: 240,
                    maxHeight: 'auto', 
                    padding:'0 16px 1em 10px',
                    align: 'bottom left',
                    skin: 'dialogSkin dialogSkin2',
                    fixed: false, 
                    quickClose: false, 
                    modal: true ,
                    backdropBackground:'#000',
                    backdropOpacity:0.7,
                    escClose:true,
                    zIndex:990  
                };
                var dialog = new Dialog(config);
                dropSelect(name,oData);
        }

        var dropSelect = function(oName,oData) {
            Util.ajax.getJson( AjaxPath.project + "/dropdown?modual=user&type=userId", {}, function(result, isok){
                /*excuterSelect = new Select({
                    el:$("#excuter"),       //要绑定的容器
                    ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置，<span class="s">慎用</span>
                        method:'GET'
                    }, 
                    label:'指定'+oName+':', //下拉框单元左侧label文本，可不配置
                    selectText:false,       //是否显示  ‘选择|清除’  模式
                    name:'excuter',    //下拉框单元右侧下拉框名称
                    disabled:false,     //组件是否被禁用
                    topOption:"请选择", //设置最顶部option的text属性
                    value:'',//初始选中项设置 默认是按value，如果你想按id设置 也可以 value:[&quot;id&quot;,1],这样设置
                    textField:"value",   //设置下拉框内容，填写数据中对应的字段名
                    valueField:"key",//设置下拉框value，填写数据中对应的字段名
                    datas: result.beans,         //数据源
                    loadAtClick:false,// true--第一次点击时渲染|false或不配置--初始化时渲染
                    // url:'../../../data/select.json'  //数据源，不建议使用，后期将会移除
                });*/
                if(result.returnCode === "0000"){
                    result.returnCode = "0";
                    for(var i =0;i<result.beans.length;i++){
                        result.beans[i].name =  result.beans[i].value;
                        result.beans[i].value = result.beans[i].key;
                    }
                    result.beans.unshift({
                            "id":"0",
                            "name":"请选择"
                    })
                    result.beans = JSON.parse(JSON.stringify(result.beans));
                }
                if(oData === undefined || oData === null || oData === "" || oData === 0){
                    oData = "0";
                }
                excuterSelect = new ComboSelect({
                    el:$("#excuter"),       //要绑定的容器
                    name:'excuter',    //下拉框单元添加name属性
                    checked:"0",        //默认选中
                    loadAtClick:false,
                    // url:'../data/select.json',  //数据源，不建议使用，后期将会移除
                    datas: result.beans         //数据源与url模式可二选一
                });
                excuterSelect.setValue(""+oData);
                /*if(oData === undefined || oData === null || oData === "" || oData === 0){
                    excuterSelect.setValue(0);
                } else {
                    excuterSelect.setValue(""+oData);
                }*/
            })
        }
        //查看用户信息
        var creatNameDialog = function(item){
            Util.ajax.getJson("/devops-auth/users/"+item.data.userId, {}, function(result, isok) {
            // Util.ajax.getJson("http://192.168.91.172:8099/devops-auth/users/"+item.data.userId, {}, function(result, isok) {    
                new Dialog({
                    mode: 'normal', 
                    title: '用户信息', 
                    content: Util.hdb.compile(formationTpl)(item), 
                    cancel: function() { 
                        return true;
                    },
                    cancelDisplay: false, //是否显示取消按钮 默认true显示|false不显示
                    width: 600, //对话框宽度，normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 300, //对话框高度，normal默认值为400，confirm默认值为180，tips默认值为80
                    maxWidth: 240,//设置tips对话框的最大宽度,默认为240px。仅在tips对话框下生效，该项存在时，width属性将失效。
                    maxHeight: 'auto', //设置tips对话框的最大高度,默认为auto。仅在tips对话框下生效，该项存在时，height属性将失效。
                    padding:'0 16px 1em 10px',//(默认值: 继承 css 文件设置) 设置消息内容与消息容器的填充边距，即 style padding属性
                    align: 'bottom left',//设置对话框与其他元素的对齐方式。仅在show(elem)与showModal(elem)传入元素时生效。默认值: "bottom left"。可选："top left" "top" "top right" "right top" "right" "right bottom" "bottom right" "bottom" "bottom left" "left bottom" "left" "left top"。
                    skin: 'dialogSkin dialogSkin2',//设置对话框额外的className参数,多个className请使用空格隔开。
                    modal: true ,//是否开启模态框状态  默认false不开启|true开启,confirm默认状态为true
                    backdropBackground:'#000',//设置遮罩颜色，默认 #000。
                    backdropOpacity:0.7, //设置遮罩透明度，默认 0.7，取值范围：0~1 。
                    zIndex:990   // 对话框的z-index值，默认是1024。
                });
                creatZtree(item.data.organId);
            });
        }
        var creatZtree = function(organId){
            Util.ajax.getJson("/devops-auth/organs/findTree/"+organId, {}, function(result, isok) {
            // Util.ajax.getJson("http://192.168.91.172:8099/devops-auth/organs/findTree/"+organId, {}, function(result, isok) {
                var setting = {
                    treeId: "ztreeContainer",      //zTree 的唯一标识，初始化后，等于 用户定义的容器的 id 属性值
                    async:{
                        enable: false
                    },
                    view:{
                        showIcon: false,     //是否显示节点图标，默认值为true
                        showLine: true,     //是否显示节点之间的连线，默认值为false
                    }
                }
				zTree = new SimpleTree.tierTree($('#ztreeContainer'), result.beans, setting);
                zTree.expandAll(true);
			});
        }       

        //弹出添加人员对话框
        var addStaffing = function(e){
            console.log($(".sn-tab.J_tab_render").height()-30,typeof ($(".sn-tab.J_tab_render").height()-30))
            var okey = null;
            if(e.currentTarget.id === "adddevelop"){
                okey = 6;
            }else if(e.currentTarget.id === "addrequire"){
                okey = 5;
            }else if(e.currentTarget.id === "addtest"){
                okey = 7;
            }
            new Dialog({
                mode: 'normal', 
                title: '添加人员', 
                content: Util.hdb.compile(addPeopleTpl)(), 
                ok: function() {
                    var data = Form.serialize($('.addForm'));
                    var arr = allPeopleList.getCheckedRows();
                    if(data.addTo === ""){
                        new Dialog({
                            mode: 'tips',
                            content: '<div style="text-align:center;margin-top:50px">请选择添加到</div>',
                            width: 300, 
                            height: 150, 
                            cancelDisplay: false
                        });
                        return false;
                    } else if(allPeopleList.getCheckedRows().length === 0){
                        new Dialog({
                            mode: 'tips',
                            content: '<div style="text-align:center;margin-top:50px">请选择至少一条数据进行提交!</div>',
                            width: 300, 
                            height: 150, 
                            cancelDisplay: false
                        });
                        return false;
                    } else {
                        var newArr=[];
                        for(var i = 0; i < arr.length; i++ ){
                            var obj = {};
                            obj.projectRoleId = data.addTo;
                            obj.userId = arr[i].userId;
                            newArr.push(obj);
                        }
                        Util.ajax.postJson(AjaxPath.project+"/projects/"+projectId+"/users/"+okey, {"json":JSON.stringify(newArr)} ,function(result, isok) {
                            var flag = result.returnCode;
                            if(flag !== '0000') {
                                new Dialog({
                                    mode: 'tips',
                                    content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>',
                                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                                    height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                                    cancelDisplay: false
                                });
                                return;
                            } else if(flag === '0000'){
                                new Dialog({
                                    mode: 'tips',
                                    content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>',
                                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                                    height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                                    cancelDisplay: false
                                });
                                allListInit();
                            }
                        })
                        return true;
                    }
                    
                }, 
                cancel: function() {
                    return true;
                },
                cancelValue: '取消', //取消按钮的文本 默认是 ‘关闭’
                okValue: '提交', //取消按钮的文本 默认是 ‘关闭’
                cancelDisplay: true, //是否显示取消按钮 默认true显示|false不显示
                width: 800, //对话框宽度，normal默认值为600，confirm默认值为300，tips默认值为240
                height: parseInt($(".sn-tab.J_tab_render").height()-120), //对话框高度，normal默认值为400，confirm默认值为180，tips默认值为80
                padding:'0 16px 1em 10px',//(默认值: 继承 css 文件设置) 设置消息内容与消息容器的填充边距，即 style padding属性
                align: 'bottom left',//设置对话框与其他元素的对齐方式。仅在show(elem)与showModal(elem)传入元素时生效。默认值: "bottom left"。可选："top left" "top" "top right" "right top" "right" "right bottom" "bottom right" "bottom" "bottom left" "left bottom" "left" "left top"。
                skin: 'dialogSkin dialogSkin2',//设置对话框额外的className参数,多个className请使用空格隔开。
                fixed: false, //是否开启固定定位 默认false不开启|true开启
                quickClose: false, //点击空白处快速关闭 默认false不关闭|true关闭
                modal: true ,//是否开启模态框状态  默认false不开启|true开启,confirm默认状态为true
                backdropBackground:'#000',//设置遮罩颜色，默认 #000。
                backdropOpacity:0.7, //设置遮罩透明度，默认 0.7，取值范围：0~1 。
                escClose:true,//esc键快速关闭对话框，默认为true
                zIndex:990   // 对话框的z-index值，默认是1024。
            });
            addDropSelectTo(e,okey);
            adddropSelectOgn();
            allList();
            // validatorEmail();
        }

        var addDropSelectTo = function(e,key) {
            Util.ajax.getJson( AjaxPath.project + "/dropdown?modual=projectRoles&type=commonRole", {}, function(result, isok){
                var addDropSelect = new Select({
                    el:$("#addTo"),       //要绑定的容器
                    ajax:{    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置，<span class="s">慎用</span>
                        method:'GET'
                    }, 
                    label:'添加到:', //下拉框单元左侧label文本，可不配置
                    selectText:false,       //是否显示  ‘选择|清除’  模式
                    name:'addTo',    //下拉框单元右侧下拉框名称
                    disabled:false,     //组件是否被禁用
                    topOption:"请选择", //设置最顶部option的text属性
                    value:'',//初始选中项设置 默认是按value，如果你想按id设置 也可以 value:[&quot;id&quot;,1],这样设置
                    textField:"value",   //设置下拉框内容，填写数据中对应的字段名
                    valueField:"key",//设置下拉框value，填写数据中对应的字段名
                    datas: result.beans,         //数据源
                    loadAtClick:false,// true--第一次点击时渲染|false或不配置--初始化时渲染
                    // url:'../../../data/select.json'  //数据源，不建议使用，后期将会移除
                });
                if( key ) {
                    addDropSelect.setValue(""+key);
                } else {
                    addDropSelect.setValue(0);
                }
            })
        }

        var adddropSelectOgn = function() {
            // Util.ajax.getJson( AjaxPath + "/organs?organType=0", {}, function(result, isok){
            // Util.ajax.getJson( 'http://192.168.91.172:8099/devops-auth/organs?organType=0', {}, function(result, isok){
                var selectTree3 = new SelectTree({
                    el:'#organization',                  //组件要绑定的容器，默认为body（此项可不配置或留空）
                    inputClassName:'',       //给所选input框添加类名，值默认为bg-tree 
                    className:'',    //弹出树面板树上添加的类名
                    label:'所属组织:',     //所选input框左侧label的名称
                    check:true,         //false时为单选，true时为多选
                    async:{
                        enable:false  //是否启用异步树
                    },         
                    name:'organId',      //所选input框兄弟元素隐藏域的名称，用于存储用户选中的值
                    text:'',            //组件初始化时，要显示在文本域中的内容
                    value:'',           //组件初始化时，要显示在隐藏域中的value值
                    textField:'name',  //用户从树上选中节点时，要显示在文本域中的内容,默认为name值
                    valueField:'id',   //用户从树上选中节点时，要显示在隐藏域中的内容
                    expandAll:false,     //默认是否展开所有节点
                    checkAllNodes:true,
                    childNodeOnly:true, //true仅仅选择子节点到文本域；false连同父级节点一同选择到文本域
                    // url:'../../../data/selectTree.json'
                    // url: 'http://192.168.91.172:8099/devops-auth/organs?organType=1'
                    url: '/devops-auth/organs/findTrees'
                    // url: '/devops-auth/organs?organType=1'
                })
                $(".texts.bg-tree").css({'backgroundColor':"#fff"});
            // })
        }

        var allList = function (){
            var config = {
                el: $('.addListContainer'),
                ajax: {    //所有jquery.ajax的配置项均可配置，这些配置将替换底层组件的配置；慎用
                    method:'GET'
                },
                field: {
                    boxType: 'checkbox',
                    key: 'id',
                    items: [
                    {
                        text: '姓名',
                        title: 'userName',
                        name: 'userName',
                        className: 'w90',
                        render: function (item, val) {
                            val = $('<span/>').text( val ).html();
                            val = val.replace(/\s/g, '&nbsp;');
                            return  val;
                        }
                    },
                    {
                        text: '用户名',
                        title: 'userAccount',
                        name: 'userAccount',
                        className: 'w90'
                    },
                    {
                        text: '手机号',
                        title: 'phone',
                        name: 'phone',
                        className: 'w90'
                    },
                    {
                        text: '邮箱',
                        title: 'email',
                        name: 'email',
                        className: 'w90'
                    }]
                },
                page: {
                    customPages: [2, 3, 5, 10, 15, 20, 30, 50], //可选择每页显示多少条
                    perPage: 5, //默认每页显示多少条记录
                    total: true
                }, 
                data: {
                    url: AjaxPath.auth + '/users'
                    // url:'http://192.168.91.172:8099/devops-auth/users'
                    // url:"../../../data/list1.json"
                }
            };
            allPeopleList = new List(config);
            allPeopleList.search();
        }

        var btnSearch = function() {
            var data = Form.serialize($('.addForm'));
            data.limit = 10;
            data.page = 1;
            // data.systemId = $cookie.get("projectSelectId");
            allPeopleList.search(data);
        }

        var btnSearchRest = function(){
            $("#userName").val("");
            $("#email").val("");
            $("input[name='sn-organId-text']").val("");
            $("input[name='organId']").val("");

            var data = {};
            // data.systemId = $cookie.get("projectSelectId");
            allPeopleList.search(data);
        }

        //删除确认对话框
        var delDialogBox = function(e) {
            var config = null;
            var nodes = null;
            var nameTip = null; 
            if(e.currentTarget.id === 'delrequire'){
                nodes = requireList.getCheckedRows();
                nameTip = '需求';
            } else if(e.currentTarget.id === 'deldevelop'){
                nodes = developList.getCheckedRows();
                nameTip = '开发';
            } else if(e.currentTarget.id === 'deltest'){
                nodes = testList.getCheckedRows();
                nameTip = '测试';
            } else if(e.currentTarget.id === ""){
                nodes = requireList.getCheckedRows().length ? requireList.getCheckedRows(): ( developList.getCheckedRows().length ? developList.getCheckedRows() : testList.getCheckedRows() );
                nameTip = requireList.getCheckedRows().length ? '需求': ( developList.getCheckedRows().length ? '开发' : '测试' );
            }
            if(nodes.length < 1 && e.currentTarget.id !== '') {
                config = {
                    mode: 'tips',
                    content: '<div style="text-align:center;margin-top:70px">请选择至少一条数据进行删除！</div>',
                    width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                    cancelDisplay: false
                };
                var dialog = new Dialog(config);
            } else {
                config = {
                    mode: 'confirm', //对话框模式，默认normal标准|tips浮动层|confirm确认对话框
                    title: "删除提示", //对话框标题
                    content: '<div style="text-align:center;margin-top:50px">确认删除选择的'+nameTip+'人员？</div>' /* + content.substring(0,content.length-1)*/ , //对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                    ok: function() {
                        delPeopleList(e,nodes);
                        return true;
                    }, // 配置该项时才会出现ok按钮，回调函数可为空。如果指定 return false 则执行完方法后不关闭对话框。默认 return true
                    okValue: '确定', //确定按钮的文本 默认是 ‘ok’
                    cancel: function() {}, //取消按钮的回调函数,配置该项时才会出现关闭按钮，回调函数可为空。
                    cancelValue: '取消', //取消按钮的文本 默认是 ‘关闭’
                    cancelDisplay: true, //是否显示取消按钮 默认true显示|false不显示
                    width: 300, //对话框宽度，normal默认值为600，confirm默认值为300，tips默认值为240
                    height: 120, //对话框高度，normal默认值为400，confirm默认值为180，tips默认值为80
                    padding: '0 16px 1em 10px', //(默认值: 继承 css 文件设置) 设置消息内容与消息容器的填充边距，即 style padding属性
                    align: 'bottom right', //设置对话框与其他元素的对齐方式。仅在show(elem)与showModal(elem)传入元素时生效。默认值: "bottom left"。可选："top left" "top" "top right" "right top" "right" "right bottom" "bottom right" "bottom" "bottom left" "left bottom" "left" "left top"。
                    skin: 'dialogSkin dialogSkin2', //设置对话框额外的className参数,多个className请使用空格隔开。
                    fixed: true, //是否开启固定定位 默认false不开启|true开启
                    quickClose: false, //点击空白处快速关闭 默认false不关闭|true关闭
                    modal: true, //是否开启模态框状态  默认false不开启|true开启,confirm默认状态为true
                    beforeOpen: function() {}, //对话框打开之前执行。
                    zIndex: 990 // 对话框的z-index值，默认是1024。
                };
                var delDialog = new Dialog(config)
            }
        };
        //删除操作
        var delPeopleList = function(e,nodes){
            var flag = null;
            handLoading = new Loading(loadingConfig);
            var oTarget = $(e.currentTarget).find('button').attr('oId');
            var oDellAll = $(e.currentTarget).attr('id');
            var data = [];
            for(var i = 0; i < nodes.length; i++) {
                data.push(nodes[i].id);
            }
            var str = JSON.stringify(data);
                if(nodes.length === 1){
                    Util.ajax.getJson(AjaxPath.project+"/projects/"+projectId+"/delete/users?userId="+nodes[0].userId+"&projectRoleId="+nodes[0].project_role_id, {} ,function(result, isok) {
                        flag = result.returnCode;
                        if(flag !== '0000') {
                            handLoading.destroy();
                            new Dialog({
                                mode: 'confirm', //对话框模式，默认normal标准|tips浮动层|tips确认对话框
                                title: '提示', //对话框标题
                                width: 300,
                                height: 120,
                                modal: true,
                                content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>', //对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                                cancelDisplay: false,
                                ok: function() {}, // 配置该项时才会出现ok按钮，回调函数可为空。如果指定 return false 则执行完方法后不关闭对话框。默认 return true
                                okValue: '关闭' //确定按钮的文本 默认是 ‘ok’
                            });
                            return;
                        } else if(flag === '0000'){
                            handLoading.destroy();
                            new Dialog({
                                mode: 'tips',
                                content: '<div style="text-align:center;margin-top:70px">删除成功！</div>',
                                width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                                height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                                cancelDisplay: false
                            });
                            if(oTarget === "delrequireListContainer" || oDellAll === "delrequire"){requireList.search();$('.requireListContainer').find('a').removeClass('theSort');}
                            else if (oTarget === "deldevelopListContainer" || oDellAll === "deldevelop"){developList.search();$('.developListContainer').find('a').removeClass('theSort');}
                            else if (oTarget === "deltestListContainer" || oDellAll === "deltest"){testList.search();$('.testListContainer').find('a').removeClass('theSort');}
                        }
                    })
                } else {
                    var newArr=[];
                    for(var i = 0; i < nodes.length; i++ ){
                        var obj = {};
                        obj.projectRoleId = nodes[i].project_role_id;
                        obj.domainId = projectId;
                        obj.userId = nodes[i].userId;
                        newArr.push(obj);
                    }
                    Util.ajax.postJson(AjaxPath.project+"/projects/"+projectId+"/batchDelete/users", {"data" : JSON.stringify(newArr)}, function(result, isok) {
                        flag = result.returnCode;
                        if(flag === '0000'){
                            handLoading.destroy();
                            new Dialog({
                                mode: 'tips',
                                content: '<div style="text-align:center;margin-top:70px">'+result.returnMessage+'</div>',
                                width: 300, //对话框宽度，可选项。normal默认值为600，confirm默认值为300，tips默认值为240
                                height: 150, //对话框高度，可选项。normal默认值为400，confirm默认值为180，tips默认值为80
                                cancelDisplay: false
                            });
                            if(e.currentTarget.id === 'delrequire'){requireList.search();$('.requireListContainer').find('a').removeClass('theSort');}
                            else if (e.currentTarget.id === 'deldevelop'){developList.search();$('.developListContainer').find('a').removeClass('theSort');}
                            else if (e.currentTarget.id === 'deltest'){testList.search();$('.testListContainer').find('a').removeClass('theSort');}
                        } else {
                            handLoading.destroy();
                            new Dialog({
                                mode: 'confirm', //对话框模式，默认normal标准|tips浮动层|tips确认对话框
                                title: '提示', //对话框标题
                                width: 300,
                                height: 120,
                                modal: true,
                                content: '<div style="text-align:center;margin-top:50px">'+result.returnMessage+'</div>', //对话框内容，可以是字符串、html片段、或dom对象,默认为loading状态（点组成的圈）
                                cancelDisplay: false,
                                ok: function() {}, // 配置该项时才会出现ok按钮，回调函数可为空。如果指定 return false 则执行完方法后不关闭对话框。默认 return true
                                okValue: '关闭' //确定按钮的文本 默认是 ‘ok’
                            });
                            return;
                        }  
                    })
                }
                
        }
        var validatorEmail = function() {
            var config = {
                el: $(".addForm"),     //要验证的表单或表单容器
                dialog:true,    //是否弹出验证结果对话框,默认false
                rules:{
                    email:'email'
                },
                messages:{
                    email:{
                        email:"邮箱格式不正确"
                    }
                }
            }
            var validator = new Validator(config);
        }
        var inProjectList = function() {
            getProjectList($cookie.get("userId"), allInit, initListTabel);
        }
        var initListTabel = function (){
            initTpl();
            allListInit();
        }
        var viewFormation = function (e){
            var $data = parseInt($(this).attr('odata'));
            Util.ajax.getJson(AjaxPath.project+"/projects/"+projectId+"/users?isLeader=true", {} ,function(result, isok) {
                for(var i=0; i < result.beans.length; i++ ){
                    if($data === result.beans[i].project_role_id){
                        var item = {};
                        item.data = result.beans[i];
                        creatNameDialog(item);
                    }
                }
            });
            // creatNameDialog(item)
        }

        var changeSlide = function (){
            var _this = $(this);
            $('.tabProjectContainer .t-list-title>span.tri').each(function (index, element) {
                if(element === _this[0] && index === 0) {
                    _this.toggleClass("tri-down").toggleClass("tri-left");
                    $("#requireWrapBlock").slideToggle();
                    if(_this.attr("class") === "tri tri-down"){
                        listInit('requireListContainer');
                        requireList = new List(listConfig);
                        requireList.search();
                        $('.requireListContainer').find('a').removeClass('theSort');
                    };
                }else if(element === _this[0] && index === 1){
                    _this.toggleClass("tri-down").toggleClass("tri-left");
                    $("#developWrapBlock").slideToggle();
                    if(_this.attr("class") === "tri tri-down"){
                        listInit('developListContainer');
                        developList = new List(listConfig);
                        developList.search();
                        $('.developListContainer').find('a').removeClass('theSort');
                    };
                }else if(element === _this[0] && index === 2){
                    _this.toggleClass("tri-down").toggleClass("tri-left");
                    $("#testWrapBlock").slideToggle();
                    if(_this.attr("class") === "tri tri-down"){
                        listInit('testListContainer');
                        testList = new List(listConfig);
                        testList.search();
                        $('.testListContainer').find('a').removeClass('theSort');
                    };
                }
            });
        }

        var allInit = function(){
            allListInit();
            projectId = $cookie.get("projectSelectId");
            initTpl();
        }
         //页面元素级权限验证
        var getStaffingAuthority = function($el){
            require(['js/btnAuthority'], function(oAuthority){
                new oAuthority($el);
            });
            Util.ajax.getJson(AjaxPath.auth + '/authority/button/'+ $cookie.get("userId") +'?datas=[{"mo":"24","btnId":""}]', {}, function(result, json){
                if(result.returnCode==="0000"){
                    if(result.beans[0].mo === 0){
                        staffingAuthority = false;
                    }else {
                        staffingAuthority = true;
                    }
                    inProjectList();
                }
            });
        }
        return initialize;
    });